package com.gopay.common.trace.aop;

import com.gopay.common.trace.helper.LogAbstractHelper;
import com.gopay.common.trace.helper.LogLocalHelper;
import com.gopay.common.trace.support.LogContext;
import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.support.AopUtils;

/**
 * 执行时间打印切面
 * Created by xuHui on 2017/4/5.
 * 废弃使用  已经改为  使用注解切面形式
 */
@Deprecated
public class ExecuteTimePrinterAspect {

    private static final Logger logger = LoggerFactory.getLogger(ExecuteTimePrinterAspect.class);

    private LogContext logContext = LogContext.getContext();

    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {

        boolean isProxy = AopUtils.isAopProxy(joinPoint.getTarget());

        //如果是代理访问 则直接执行
        if (isProxy) {
            return joinPoint.proceed();
        }

        LogAbstractHelper helper = new LogLocalHelper();

        helper.beforeT(joinPoint);

        Object returnValue = null;
        try {
            returnValue = joinPoint.proceed();
        } catch (Throwable throwable) {
            helper.exT(throwable);
            throw  throwable;
        } finally {
            helper.afterT(joinPoint);
        }
        return returnValue;
    }
}
